local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.Client_PlayerComponent(),"HomeButton_"..script.Name);

local gUnlockLevel=3 --战斗引导等级

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);

    self.player=self.parent
	self.DataStore=self.parent:GetComponent(_G.ClientOHOH.load.Client_PlayerDataComponent())

    self.BeamLineCtrl=self.parent:GetComponent(ClientOHOH.load.Client_BeamLineCtrl())

    self.ConList={}
    local con= self.parent.BattleSateEvent:Connect(function(isBattle)
        if isBattle then
            self:CloseLine()
        end
	end)
    table.insert( self.ConList,con)

    local con2= self.parent.LevelChangeEvent:Connect(function(level)
        self:UpdData(level,self.DataStore:GetData("base").rebirth)
	end)
    table.insert(self.ConList,con2)

    self:UpdData(self.DataStore:GetData("base").level,self.DataStore:GetData("base").rebirth)
end;


function M.ShowLine(self)

    self:AddProcess(function()
        while not self.player.character do
            self:Wait(1.5)
        end
        
        while not self.player.character.main_inst do
            self:Wait(1.5)
        end

        local ready=_G.client:GetComponent(_G.CommonOHOH.load.ReayBattleCtrl()):FindNearBattleReady(self.player.character); 
        self.LineId="GUDIE"
        self.BeamLineCtrl:CreateLine(ready:GetEnterTouch(),self.LineId)

    end)

end

function M.CloseLine(self)
    if self.LineId then
        self.BeamLineCtrl:DestoryLine(self.LineId)
    end
    self:dtor()
end


function M.UpdData(self,level,rebirth)
    if self.LineId then
        return 
    end
    
    if level>gUnlockLevel then
        self:CloseLine()
    elseif rebirth>0 then
        self:CloseLine()
    elseif level==gUnlockLevel then
        self:ShowLine()
    end
end

function M.dtor(self)
     for k,v in pairs(self.ConList) do
        v:Disconnect()
     end
     self.ConList={}
	M.super.dtor(self);
end;

return M